package com.fruit.controller.wap.recommend;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fruit.controller.base.BaseController;
import com.fruit.pojo.recommend.Recommend;
import com.fruit.service.recommend.RecommendManager;
import com.fruit.util.DateUtil;
import com.fruit.util.ResultInfo;

import lombok.extern.slf4j.Slf4j;

/**
 * 
 * @ClassName: GoodsWapController
 * @author 葛欢欢
 * @version 2017.11.30 12:20
 */
@Slf4j
@Controller
@RequestMapping(value = "/wap/")
public class RecommendWapController extends BaseController {

	@Autowired
	private RecommendManager recommendManager;


	
	/**
	 * 广告位
	 * @param request request
	 * @param session session
	 * @return Map<String, Object>
	 * @author 葛欢欢
	 * @version 2017.11.30 12:20
	 */
	@RequestMapping(value = "/recommend", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Map<String, Object> recommendList(String position,HttpServletRequest request, HttpSession session) {
		long a = System.currentTimeMillis();
		log.info("【广告位列表进入时间】" + DateUtil.getTime());
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			List<Recommend> recommend = recommendManager.findRecommendByPosition(position);
			resultMap.put("recommend", recommend);
			resultMap.put("result", this.initResult(ResultInfo.SUCCESS, "ok", ""));
		} catch (Exception e) {
			e.printStackTrace();
			resultMap.put("result", this.initResult(ResultInfo.ERROR, "exception", "系统异常"));
		}
		
		log.info("【广告位列表】---【结束】---");
		log.info("【广告位列表耗时】" + (System.currentTimeMillis() - a) / 1000f + "秒");
		return resultMap;
	}
}
